<?php
class Henry_Contents extends Zend_Db_Table_Abstract
{
	protected $_name = 'contents'; 
  	protected $_primary = array('contents_key','language');
	public function __construct() {
        parent::__construct();
        $dbconfig = $this->_db->getConfig();
        $this->_name = $dbconfig['prefix'].'contents';
    }
	public function checkExists($key,$lang)
	{
		$select = $this->_db->select();
		$select->from($this->_name,'contents_key')
				->where('contents_key = ?',$key)
				->where('language = ?',$lang);
		$data = $this->_db->fetchOne($select);
		return !empty($data);
	}
	public function editContent($data)
	{        
		$where[] = $this->_db->quoteInto('contents_key = ?',$data['contents_key']);
		$where[] = $this->_db->quoteInto('language = ?',$data['language']);
		return $this->update($data, $where);
	}
	public function getAllbyKey($key)
	{
		$lang = new Henry_Languages();
		$select = $this->_db->select();
		$select->from(array('l' => $lang->info(Henry_Languages::NAME)),'*')
				->joinLeft(array( 'c' => $this->_name), "l.key = c.language and contents_key = '$key'", '*');
		return $this->_db->fetchAll($select);
	}
}